package com.pingtai.security.support;

import java.io.IOException;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;

import com.opensymphony.xwork2.ActionContext;

public class ValidateCodeDispatcher implements AuthenticationSuccessHandler {

	
    
	@Override
	public void onAuthenticationSuccess(HttpServletRequest request,
			HttpServletResponse response, Authentication arg2) throws IOException,
			ServletException {
		
		String rightValidateCode = (String)request.getSession().getAttribute(com.google.code.kaptcha.Constants.KAPTCHA_SESSION_KEY);
		String validateCode = request.getParameter("validateCode");
		if(!validateCode.equalsIgnoreCase(rightValidateCode)){
			response.sendRedirect(request.getContextPath()+"/login.jsp?v=false");
		}else{
			request.getSession().setAttribute("userName", request.getParameter("j_username"));
			//request.getRequestDispatcher(request.getContextPath()+"/index").forward(request, response);
			response.sendRedirect(request.getContextPath()+"/loginSuccess.jsp");
		}

	}

}
